extends "cutscene.gd"

var hp = 0
var hpmax = 1
var timer
var snd
var cp
var boss
var state = 0

# Called when the node enters the scene tree for the first time.
func _ready():
	super._ready()
	set_physics_process(false)
	check = "1ArenaBeat"
	timer = get_node("Timer")
	text = ["You got a Lifeforce Crystal!", "Your shield will regenerate faster now."]
	var test = get_node("/root/Progress").checks
	cp = get_node("Checkpoint")
	if (test[check]):
		cp.position = Vector2(0,0)
		cp.show()
	snd = get_node("/root/SoundManager")
	boss = get_node("Boss")

func _physics_process(delta):
	if (state == 1):
		if (hp < hpmax):
			snd.play_sfx("dot",true)
			hp += 0.25
			controller.bosshp.update(hp)
		else:
			timer.start()
			state = 2
	if (state == 2):
		if (boss.hp > 0):
			controller.bosshp.update(boss.hp)
		else:
			controller.hide_bosshp()
			controller.begin_cutscene()
			state = 3
			timer.start()
			set_physics_process(false)

func begin_cutscene():
	state = 0
	controller.cam_target = self
	get_node("Timer").start()

func want_save():
	pass

func shake():
	controller.is_shaking = true

func rumble():
	controller.snd_manager.play_sfx("rumble")

func _on_Timer_timeout():
#	snd.change_song()
	if (state == 0):
		state = 1
		get_node("Walls").play("close")
		timer.start()
	elif (state == 1):
		hpmax = boss.hp
		hp = 0
		controller.show_bosshp(hpmax)
		set_physics_process(true)
	elif (state == 2):
		boss.active = true
		controller.end_cutscene()
	elif (state == 3):
		var player = controller.get_player()
		controller.cam_target = player
#		controller.snd_manager.play_sfx("fanfare")
		controller.change_face("excited")
		player.top_anim.play("victory")
		player.bot_anim.play("victory")
		player.effects.play("upShield")
		controller.begin_cutscene()
		controller.show_text(text)
		var progress = get_node("/root/Progress").checks
		progress[check] = true
		progress["1ShieldUpgrade"] = true
		get_node("Walls").play("open")
		cp.position = Vector2(0,0)
		get_node("CP").play("fade")
		cp.show()
